<template>
  <div class="home">
    <h1>home</h1>
    <el-table
        :data="dataList"
        style="width: 100%">
      <el-table-column
          prop="id"
          label="ID"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="age"
          label="年龄">
      </el-table-column>
      <el-table-column
          prop="sex"
          label="性别">
      </el-table-column>
    </el-table>

    <el-button type="primary" @click="goAboutPage">主要按钮</el-button>
  </div>
</template>

<script>
export default {
  name: 'HomeView',
  components: {},
  data() {
    return {
      user: {},
      dataList: [],
      msg: "good",
    }
  },
  created() {
    this.user = this.$route.query;
    console.log("user", this.user);
    console.log("name", this.user.name);
    console.log("id", this.user.id);
    this.initRequest();
    this.initRequest();
  },
  methods: {
    goAboutPage() {
      this.$router.push({
        name: 'about',
        params: {
          id: 10,
          name: "霍去病"
        }
      })
    },
    // goAboutPage(){
    //   this.$router.push({
    //     path:"/about",
    //     query:{
    //       id:10,
    //       name:"霍去病"
    //     }
    //   })
    // },
    initRequest() {
      console.log(this);
      this.$axios({
        url: '/student/findAll',
        method: 'GET',
        params: {}
      }).then(res => {
        console.log(res.data);
        this.dataList = res.data;
      }).catch(err => {
        console.log(err);
      })
    },

    // initRequest2(){
    //   this.$axios({
    //     url: 'https://mock.presstime.cn/mock/655dbc73d77728f09c299c52/changan9527/user',
    //     method: 'GET',
    //     params: {
    //     }
    //   }).then(res => {
    //     console.log(res);
    //     this.dataList = res.data.data;
    //   }).catch(err => {
    //     console.log(err);
    //   })
    // }
  }
}
</script>
